
#ifndef __SPI_H
#define __SPI_H
#include "xc.h"
#define  SPRE_1_1   7    // Auxiliary predivision ratio 1:1
#define  SPRE_2_1   6    // Auxiliary predivision ratio 2:1
#define  SPRE_3_1   5    // Auxiliary predivision ratio 3:1
#define  SPRE_4_1   4    // Auxiliary predivision ratio 4:1
#define  SPRE_5_1   3    // Auxiliary predivision ratio 5:1
#define  SPRE_6_1   2    // Auxiliary predivision ratio 6:1
#define  SPRE_7_1   1    // Auxiliary predivision ratio 7:1
#define  SPRE_8_1   0    // Auxiliary predivision ratio 8:1

#define  PPRE_1_1   3    // Main pre-frequency ratio 1:1
#define  PPRE_4_1   2    // Main pre-frequency ratio 4:1
#define  PPRE_16_1  1    // Main pre-frequency ratio 16:1
#define  PPRE_64_1  0    // Main pre-frequency ratio 64:1


#define Framehead_SPI   0xAA 


#define  SPI_CMD_Read     0x00
#define  SPI_CMD_Write    0x01






typedef struct _SPI_STRUCT {
    unsigned char Head;            // Frame Header
    unsigned char Cmd;             // CMD
    unsigned char Data[9];         // Data   
    unsigned char CheckSum;        // checksum 

} SPI_STRUCT;
//extern SPI_STRUCT SPI_Tx_Msg; 
//extern SPI_STRUCT SPI_Rx_Msg; 


extern void Delay(void );
extern void Delay_5uS(void);   // @FCY=60MHZ
extern void Write_SPI2(unsigned int command );
extern void Write_SPI3(unsigned int command );
extern void Write_SPI4(unsigned int command );
extern void Write_SPI5(unsigned int command );
extern void Write_SPI6(unsigned int command );
uint16_t WriteExchange_SPI2(uint16_t data);
uint16_t WriteExchange_SPI3(uint16_t data);
uint16_t WriteExchange_SPI4(uint16_t data);
uint16_t WriteExchange_SPI5(uint16_t data);
uint16_t WriteExchange_SPI6(uint16_t data);

void delay(uint32_t count);
//extern void Init_SPI (void);
//extern void SPI_Data_Init(void);
//extern unsigned char SPI_TxRx_Msg(SPI_STRUCT* msg);
#endif

